/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.vraptor.jpessoal.DAO;

import br.com.caelum.vraptor.ioc.Component;
import br.com.vraptor.jpessoal.bean.InstituicaoFinanceira;
import br.com.vraptor.jpessoal.util.HibernateUtil;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author rober
 */
@Component
public class InstituicaoFinanceiraDAO {
    
    public List<InstituicaoFinanceira> listar(){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Query query = session.createQuery("from InstituicaoFinanceira");
        List<InstituicaoFinanceira> lista = query.list();
        session.getTransaction().commit();
                
        return lista;        
    }
    
    public List<InstituicaoFinanceira> listar(String where){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Query query = session.createQuery("from InstituicaoFinanceira WHERE :where");
        query.setParameter("where", where);
        List<InstituicaoFinanceira> lista = query.list();
        session.getTransaction().commit();
                
        return lista;   
    }
    
     public InstituicaoFinanceira obterPorId(Integer id){
        
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Query query = session.createQuery("from InstituicaoFinanceira where id = :id ");
        query.setParameter("id", id);
        InstituicaoFinanceira instituicaoFinanceira = (InstituicaoFinanceira) query.uniqueResult();
        session.getTransaction().commit();
                
        return instituicaoFinanceira;
    }
     
     public void salvar(InstituicaoFinanceira InstitucaoFinanceira){
         
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        session.save(InstitucaoFinanceira);
        session.getTransaction().commit();
        
         
         
     }
     
     public void atualizar(InstituicaoFinanceira InstitucaoFinanceira){
         
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        session.update(InstitucaoFinanceira);
        session.getTransaction().commit();
         
     }
    
}
